package resources.student;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import model.student.Direction;
import dao.Linker;
import dao.StudentDAO;

public class DirectionRes
{
	@Context
	UriInfo uriInfo;
	
	@Context
	Request request;
	
	String directionId;
	
	public DirectionRes(UriInfo uriInfo, Request request, String directionId) 
	{
		this.uriInfo = uriInfo;
		this.request = request;
		this.directionId = directionId;
	}
	
	@GET
	@Produces(MediaType.TEXT_XML)
	public Direction getDataBrowser() 
	{
		Linker.sort();
		
		Direction direction = StudentDAO.getDirectionsCP().get(directionId);
		
		if(direction == null)
			throw new RuntimeException("Get: Direction with " + directionId +  " not found");
		return direction;
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Direction getDataBrowserJSON() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XHTML_XML)
	public Direction getDataBrowserXHTML() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XML)
	public Direction getDataBrowserXML() 
	{
		return getDataBrowser(); 
	}
	
	@Path("{group}")
	public GroupRes getGroup(@PathParam("group") String id) 
	{
		return new GroupRes(uriInfo, request, id);
	}
}